﻿{{!<Layout}}
{{ViewBag Title='历史记录'}}

{{#if ViewBag.HistoryEnabled}}

{{#if Model}}
<div class="ui message">
    <i class="info circle icon"></i>
    History is periodically purged. Only recent job executions are shown.
</div>
{{/if}}

<div id="msg-panel"></div>

<table class="ui single line table highlight-rows" id="history-list">
    <thead>
        <tr>
            <th>Job</th>
            <th>Trigger</th>
            <th>Scheduled Fire Time</th>
            <th>Actual Fire Time</th>
            <th>Finished Time</th>
            <th>Run Time</th>
            <th>Log</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        {{#each Model}}
        <tr>
            <td class="job-key">
                <i class="{{StateIcon}} icon" title="{{State}}"></i>
                <a href="{{ActionUrl 'Edit' 'Jobs' group=JobGroup name=JobName}}">{{JobGroup}}.{{JobName}}</a>
            </td>
            <td><a href="{{ActionUrl 'Edit' 'Triggers' group=TriggerGroup name=TriggerName}}">{{TriggerGroup}}.{{TriggerName}}</a></td>
            <td>{{ScheduledFireTime}}</td>
            <td>{{ActualFireTime}}</td>
            <td>{{FinishedTime}}</td>
            <td>{{Duration}}</td>
            <td>
                {{#if Entity.EnableLog}}
                <a onclick="show_log(this)" data-content="{{ActionUrl 'View' 'Logs' id=Entity.FireInstanceId}}" style="cursor: pointer">view</a>
                &nbsp;
                <a href="{{ActionUrl 'Download' 'Logs' id=Entity.FireInstanceId}}" target="_blank">download</a>                
                {{/if}}
            </td>
            <td>
                <a onclick="detele_his('{{Entity.FireInstanceId}}')" style="cursor: pointer"><i class="left large red trash alternate outline icon"></i>Delete</a>
            </td>
        </tr>
        {{#if Entity.ExceptionMessage}}
        <tr>
            <td colspan="8">
                <div class="ui accordion">
                    <div class="title">
                        <i class="dropdown icon"></i>
                        {{Entity.ExceptionMessage}}
                    </div>
                    <div class="content">
                        <textarea readonly="readonly" cols="88" rows="10" style="width:100%">{{Entity.ExceptionDetail}}</textarea>
                    </div>
                </div>
            </td>
        </tr>
        {{/if}}
        {{/each}}
    </tbody>
</table>

{{#unless Model}}
{{>EmptyList ''}}
{{/unless}}
{{else}}
<div class="ui negative message">
    <div class="header" style="margin-bottom: 0.5em">Job history is not available.</div>
    Enable ExecutionHistoryPlugin in Quartz configuration section.
</div>
{{/if}}

<div class="ui mini modal" id="delete-dialog">
    <div class="content">
        <p>Are you sure you want to delete this history?</p>
        <p><b class="confirm-item"></b></p>
    </div>
    <div class="actions">
        <div class="ui approve red button">Delete</div>
        <div class="ui cancel button">Cancel</div>
    </div>
</div>

<div class="ui large modal" id="log-dialog">
    <div class="header">Log</div>
    <div class="content">
        <textarea id="log-content" readonly="readonly" cols="88" rows="40" style="width:100%"></textarea>
    </div>
</div>

<script>
    function detele_his(id)
    {
        $('#delete-dialog .confirm-item').text(id);
        deleteItem(id, $('#msg-panel'), '{{ActionUrl "Delete"}}', '{{ActionUrl ""}}');
    }

    function show_log(event)
    {
        var logUrl = event.dataset.content;
        $('#log-dialog')
            .modal({
                duration: 250,
                onVisible: function () {
                    $('#dimmer').dimmer('show');
                    $.ajax({
                        type: 'GET',
                        url: logUrl,
                        cache: false,
                        success: function (data) {
                            $('#log-content').text(data);
                        },
                        error: function (e) {
                            $('#dimmer').dimmer('hide');
                            prependErrorMessage(e, $('#msg-panel'));
                        }
                    });

                }
            })
            .modal('show');
    }
</script>